var  BASE = BASE||{}; //全局公用方

BASE.BLOGCOMMON = (function () {
    function uploadProjectfile(obj) {
        BASE.UPLOADANSWER.uploadFile(obj,function (url) {
            var name = obj.files[0].name || '附件';
            BASE.clearpop('上传成功');
            $('body').data('file-url',url);
            $('#fileUrlLink').fadeIn().find('span').text(name);
        })
    }
    /*删除需求文件*/
    function removeFile() {
        $('body').data('file-url',null);
        $('#fileUrlLink').fadeOut();
    }


    /*获取新增的数据*/
    function getAddData() {
        var sendData = {
            title: $('#title').val(),
            content: BASE.UPLOADANSWER.ue.txt.html(),
            covers: BASE.POPUP.getCovers().join(' '),
            categoryId: $('#interestChildData option:selected').val() ||  $('#interestData option:selected').val(),
            attachUrl:$('body').data('file-url'),
            panUrl:$('#fileLink').val(),
            panPwd:$('#filePas').val(),
            contentPrice:$('#contentPrice').val(),
            attachPrice:$('#attachPrice').val(),
            contentSupportPays:$('input[name="content-pay-type"]:checked').val(), //文章人民币金币*/
            attachSupportPays:$('input[name="attach-pay-type"]:checked').val(), //附件人民币金币*/
            replyShowIs:$('#down_type').is(':checked'), //附件
        };
        var conPayType = $('input[name="content-price-type"]:checked').val(); //免费收费
        var attachPayType = $('input[name="attach-price-type"]:checked').val(); //免费收费
        if(conPayType == 2){ //免费
            sendData.contentPrice = 0;
        }
        if(attachPayType ==2){
            sendData.attachPrice = 0;
        }
        if( attachPayType ==1){
            delete sendData.replyShowIs;
        }
        if(!sendData.title){
            BASE.clearpop('请输入项目标题');
            $('#title').trigger('click');
            return false;
        }
        if(sendData.title.length<5){
            BASE.clearpop('标题最少5字');
            $('#title').trigger('click');
            return false;
        }
        if(!sendData.content){
            BASE.clearpop('请输入项目简介');
            return false;
        }
        if(sendData.contentPrice>0 && sendData.content.length<300){
            BASE.clearpop('收费文章内容最少300字');
            return false;
        }
        if(conPayType == 1){
            if(!sendData.contentPrice){
                BASE.clearpop('请输入博文价格');
                return false;
            }
            if(!sendData.contentSupportPays){
                BASE.clearpop('请选择博文支付方式');
                return false;
            }
        }
        if(attachPayType == 1){
            if(!sendData.attachPrice){
                BASE.clearpop('请输入附件价格');
                return false;
            }
            if(!sendData.attachSupportPays){
                BASE.clearpop('请选择附件支付方式');
                return false;
            }
        }
        return sendData;
    }
    
    return{
        removeFile:removeFile,
        uploadProjectfile:uploadProjectfile,
        getAddData:getAddData,
    }
})();

/**
 * Created by EDZ on 2018/10/19.
 */
